// subpackModule/pages/physicalCondition/qrcodeEmployee/qrcodeEmployee.js

const app = getApp()
const util = app.globalData.util
const networkUtil = app.globalData.networkUtil

const logPrefix = "physicalCondition.qrcodeEmployee"

Page({

    /**
     * 页面的初始数据
     */
    data: {
        idcardno: null,
		employeeno: null,
		employeename: null,
		
        //复工状态(0 不可复工; 1 可复工;)
        returnToWork: 0,
        qrcodeStr_returnToWork: null,

        //走马灯
		text:'少出门，少聚集，勤洗手，勤通风',
        marqueePace: 2, //滚动速度
        marqueeDistance: 0, //初始滚动距离
        size: 14,
        orientation: 'left', //滚动方向
        interval: 20, // 时间间隔
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        //console.info(logPrefix+" 执行了onLoad()方法..")
        /**
         * 获取员工 "复工二维码"
         */
        let that = this
        that.setData({
            idcardno: app.globalData.wxUser.idcardno,
			employeeno: app.globalData.wxUser.employeeNo,
			employeename: app.globalData.wxUser.name
        })

        //1-1、获取员工复工状态
        that.getReturnToWork().then((res) => {
            //1-2、获取员工复工二维码
            if (app.globalData.SUCCESS_STR == res) {
                //若不可复工
                if (that.data.returnToWork == 0) {
                    that.setData({
                        qrcodeStr_returnToWork: app.globalData.wxUser.qrcodeStr_cannotReturnToWork
                    })
                }
                //若可复工
                if (that.data.returnToWork == 1) {
                    that.setData({
                        qrcodeStr_returnToWork: app.globalData.wxUser.qrcodeStr_canReturnToWork
                    })
                }
            }
        })
    },

    /**
     * 获取员工复工状态(0 不可复工; 1 可复工;)。
     */
    getReturnToWork: function() {
        let that = this
        let url = app.globalData.baseUrl + "/employee/getReturnWorkState"
        let requestData = {
            idcardno: that.data.idcardno
        }

        return networkUtil.request_get(url, requestData).then((res) => {
            //若已获取到
            that.setData({
                returnToWork: res.data
            })
            return app.globalData.SUCCESS_STR
        }).catch((res) => {
            //若未获取到
            console.error(logPrefix + " 获取员工复工信息出错!", res)
            util.showToastWithMsg("获取员工复工信息出错!", res.message)
            return app.globalData.ERROR_STR
        })
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
	onShow: function () {
		// 页面显示
		var that = this;
		var length = that.data.text.length * that.data.size;//文字长度
		var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
		that.setData({
			length: length,
			windowWidth: windowWidth,
		});
		that.runMarquee();// 水平一行字滚动完了再按照原来的方向滚动
	},
	runMarquee: function () {
		var that = this;
		var interval = setInterval(function () {
			//文字一直移动到末端
			if (-that.data.marqueeDistance < that.data.length) {
				that.setData({
					marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
				});
			} else {
				clearInterval(interval);
				that.setData({
					marqueeDistance: that.data.windowWidth
				});
				that.runMarquee();
			}
		}, that.data.interval);
	},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})
